<?php

namespace app\system\controller;

use app\system\model\DictTypeModel;
use think\App;

/**
 * 数据字典信息
 *
 * @author xuxiwang
 */
class DictType extends Base
{
    private $dictTypeModel;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->dictTypeModel = new DictTypeModel();
    }

    public function list()
    {
        $param = $this->request->param();
        $info = $this->dictTypeModel->paginate([
            'page'=>$param['pageNum'],
            'list_row'=>$param['pageSize']
        ])->toArray();

        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功',
            'rows'=> $info['data'],
            'total'=> $info['total']
        ];
        return json($returnData);
    }


    public function export()
    {

    }

    /**
     * 查询字典类型详细
     */
    public function getInfo($id)
    {
        $info = $this->dictTypeModel->find($id);
        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功',
            'data'=> $info
        ];
        return json($returnData);
    }

    /**
     * 新增字典类型
     */
    public function add()
    {
        $param = $this->request->param();
        $this->dictTypeModel->save($param);
        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功',
        ];
        return json($returnData);
    }

    /**
     * 修改字典类型
     */
    public function edit()
    {
        $param = $this->request->param();
        $this->dictTypeModel->save($param);
        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功',
        ];
        return json($returnData);
    }

    /**
     * 删除字典类型
     */
    public function remove()
    {

    }

    /**
     * 刷新字典缓存
     */
    public function refreshCache()
    {

    }

    /**
     * 获取字典选择框列表
     */
    public function optionselect()
    {
        $dataList = $this->dictTypeModel->select();

        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功',
            'data'=> $dataList
        ];
        return json($returnData);
    }
}